package ejercicio5;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Monitor {
	
	private int clientes;
	final Lock lock = new ReentrantLock();
	final Condition noClientes = lock.newCondition();
	
	public Monitor() {
		super();
		this.clientes = 0;
	}

	public void barbero(Thread th){
		while(true){
			try {
				lock.lock();
				if(clientes==0){
					System.out.println("No hay clientes, me voy a dormir");
					noClientes.await();
					System.out.println("Me acaba de despertar un cliente");
					}
				lock.unlock();
				System.out.println("Iniciando corte de pelo");
				th.suspend();
				System.out.println("He acabado de cortar el pelo");
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}//fin del while
		
	}
	
	public void cliente(Thread th){
		lock.lock();
		if(clientes>0)
		
	}

}
